package v1

import (
	"github.com/gin-gonic/gin"
	"pay/bll"
	"pay/model"
	"pay/server/web/middleware"
	"pay/utils"
)

var FeePlanPaymentOrder = &feePlanPaymentOrder{}

func init() {
	RegisterRouter(FeePlanPaymentOrder)
}

type feePlanPaymentOrder struct{}

// Init
func (a *feePlanPaymentOrder) Init(r *gin.RouterGroup) {
	g := r.Group("/feePlanPaymentOrder", middleware.Auth())
	{
		g.POST("/create", a.create)
		g.POST("/update", a.update)
		g.POST("/list", a.list)
		g.POST("/delete", a.delete)
		g.POST("/detail", a.find)
	}
}

// create
func (a *feePlanPaymentOrder) create(c *gin.Context) {
	var (
		in  = &model.FeePlanPaymentOrderCreateRequest{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		_ = c.Error(err)
		return
	}

	if _, err = bll.FeePlanPaymentOrder.Create(c.Request.Context(), in); err != nil {
		_ = c.Error(err)
		return
	}
	utils.ResponseOk(c, nil)
}

// update
func (a *feePlanPaymentOrder) update(c *gin.Context) {
	var (
		in  = &model.FeePlanPaymentOrderUpdateRequest{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		_ = c.Error(err)
		return
	}

	if err = bll.FeePlanPaymentOrder.Update(c.Request.Context(), in); err != nil {
		_ = c.Error(err)
		return
	}
	utils.ResponseOk(c, nil)
}

// list
func (a *feePlanPaymentOrder) list(c *gin.Context) {
	var (
		in  = &model.FeePlanPaymentOrderListRequest{}
		out = &model.FeePlanPaymentOrderListResponse{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		_ = c.Error(err)
		return
	}

	if out, err = bll.FeePlanPaymentOrder.List(c.Request.Context(), in); err != nil {
		_ = c.Error(err)
		return
	}
	utils.ResponseOk(c, out)
}

// list
func (a *feePlanPaymentOrder) find(c *gin.Context) {
	var (
		in  = &model.FeePlanPaymentOrderInfoRequest{}
		out = &model.FeePlanPaymentOrderInfo{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		_ = c.Error(err)
		return
	}

	if out, err = bll.FeePlanPaymentOrder.Find(c.Request.Context(), in); err != nil {
		_ = c.Error(err)
		return
	}
	utils.ResponseOk(c, out)
}

// delete
func (a *feePlanPaymentOrder) delete(c *gin.Context) {
	var (
		in  = &model.FeePlanPaymentOrderDeleteRequest{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		_ = c.Error(err)
		return
	}

	if err = bll.FeePlanPaymentOrder.Delete(c.Request.Context(), in); err != nil {
		_ = c.Error(err)
		return
	}
	utils.ResponseOk(c, nil)
}
